#ifndef STATUSINDICATOR_H
#define STATUSINDICATOR_H

#include <QLabel>
#include <QTimer>
#include <QEnterEvent>

class StatusIndicator : public QLabel
{
    Q_OBJECT

public:
    enum DeviceStatus {
        NotSelected,  // 未选择
        Selected,     // 已选择但未连接
        Connected,    // 已连接
        Working       // 正在工作
    };

    explicit StatusIndicator(const QString &deviceName, QWidget *parent = nullptr);

    void setStatus(DeviceStatus status);
    void setDataQuality(double quality);

    // 添加设置标签字体的方法
    void setLabelFont(const QFont &font);

signals:
    // 添加点击信号
    void clicked();

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;

private slots:
    void updateBlink();

private:
    // 修改为水平布局的尺寸
    static const int INDICATOR_WIDTH = 150;  // 增加宽度以容纳水平布局
    static const int INDICATOR_HEIGHT = 40;  // 减小高度以适应菜单栏
    static const int TEXT_LEFT_MARGIN = 10;  // 文字左边距

    QString m_deviceName;
    DeviceStatus m_currentStatus;
    double m_dataQuality;
    bool m_blinkState;
    bool m_hovered;
    QTimer *m_blinkTimer;
    QFont m_labelFont;  // 添加字体成员变量

    QColor getStatusColor() const;
    void setupBlink();
    void updateToolTip();
};

#endif // STATUSINDICATOR_H
